<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="static/html5shiv.js"></script>
<script type="text/javascript" src="static/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/friends/widget_ccf50cd.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/h-ui.admin/css/style.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/layer/2.4/skin/layer.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/magic-input.min.css" />
<!--[if IE 6]>
<script type="text/javascript" src="static/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>添加好友</title>
<style type="text/css">
body .mySkin .layui-layer-title {
    padding: 0 80px 0 20px;
    height: 42px;
    line-height: 42px;
    border-bottom: 1px solid #c4dbfe;
    font-size: 14px;
    color: #333;
    overflow: hidden;
    background-color: #f2f6fd;
    border-radius: 4px 4px 0 0;
    
}
</style>
</head>
  
<body>
<input type="hidden" id="search-friend">
<div class="addFriend-dialog" style="display: block;left: 383px;top: 336px">
	<div class="dlg-bd">
		<div class="search-content">
			<p class="search-title">输入大岭山中学网盘帐号添加好友：</p>
			<div class="search-area">
				<form action="javascript:void(0)" class="search-form">
					<input type="text" autocomplete="off" class="input-text" placeholder="用户名/邮箱" style="width: 410px;height: 34px">
					<a class="btn btn-primary radius" style="margin-left:5px;height: 34px;width: 70px" id="search" href="javascript:;">搜 索</a>
				</form>
			</div>
			<div class="search-result" style="display: none;">
				<p class="search-result-text">搜索结果：</p>
				<div class="search-result-area global-clearfix"></div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript" src="${pageContext.request.contextPath}/static/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="${pageContext.request.contextPath}/static/layer/2.4/layer.js"></script>

<script type="text/javascript" src="${pageContext.request.contextPath}/static/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
$(function(){
	var index = parent.layer.getFrameIndex(window.name);
	$('.input-text').focus();
	
	$(".input-text").bind("keypress",function(event){
		if(event.keyCode == "13"){
			$("#search").click();
		}
	});

	$("#search").click(function(){
		if($(".input-text").val() != ""){
			var i;
			$.ajax({
				url: "/nebula/friends/search-friend.action",
				data : {
					str : $(".input-text").val()
				},				
				dataType: "json",
				beforeSend: function () {  
                i = layer.msg('正在搜索用户，请稍后...', {icon: 16,shade: [0.5, '#f5f5f5'],scrollbar: false,offset: '0px', time:100000}) ;  
           		},
				success: function(data){
					$(".search-result").show();
					layer.close(i);
					if(data.status == 0){
						if(data.msg == "（自己）"){
							$(".search-result-area").html(
								'<a class="search-avatar" href="javascripy:;">'
									+'<img alt="'+data.data.encryptionName+'" src="${pageContext.request.contextPath}/static/avatars/user.jpg">'
								+'</a>'
								+'<div class="search-info global-clearfix no-nick-name">'
									+'<p class="search-name-add" style="display: none;">'
										+'<span class="search-name-yourself">(已是好友)</span>'
									+'</p>'
									+'<p class="search-bd-account" style = "width:400px">'
										+'<span class="search-bd-name" title="'+data.data.username+'">大岭山中学网盘账号：'+data.data.username+'</span>'
										+'<span class="search-name-yourself">'+data.msg+'</span>'
									+'</p>'
								+'</div>');
							$(".search-result-area").css("height","50px");
						}else if(data.msg == "（已是好友）"){
							$("#search-friend").val(data.data.username);
							$(".search-result-area").css("height","");
							$(".search-result-area").html(
								'<a class="search-avatar" href="javascripy:;">'
									+'<img alt="'+data.data.encryptionName+'" src="${pageContext.request.contextPath}/static/avatars/user.jpg">'
								+'</a>'
								+'<div class="search-info global-clearfix no-nick-name">'
									+'<p class="search-name-add" style="display: none;">'
										+'<span class="search-name-yourself">(已是好友)</span>'
									+'</p>'
									+'<p class="search-bd-account" style = "width:400px">'
										+'<span class="search-bd-name" title="'+data.data.encryptionName+'">大岭山中学网盘账号：'+data.data.encryptionName+'</span>'
										+'<span class="search-name-yourself">'+data.msg+'</span>'
									+'</p>'
								+'</div>'
								+'<div class="search-btn-area">'
									+'<a class="btn btn-primary radius" id="share-file">分享文件</a>'
								+'</div>');
						}else{
							$("#search-friend").val(data.data.username);
							$(".search-result-area").css("height","");
							$(".search-result-area").html(
								'<a class="search-avatar" href="javascripy:;">'
									+'<img alt="'+data.data.encryptionName+'" src="${pageContext.request.contextPath}/static/avatars/user.jpg">'
								+'</a>'
								+'<div class="search-info global-clearfix no-nick-name">'
									+'<p class="search-name-add" style="display: none;">'
										+'<span class="search-name-yourself">(已是好友)</span>'
									+'</p>'
									+'<p class="search-bd-account" style = "width:400px">'
										+'<span class="search-bd-name" title="'+data.data.encryptionName+'">大岭山中学网盘账号：'+data.data.encryptionName+'</span>'
										+'<span class="search-name-yourself">'+data.msg+'</span>'
									+'</p>'
								+'</div>'
								+'<div class="search-btn-area">'
									+'<a class="btn btn-primary radius" id="add-friend">加为好友</a>'
								+'</div>');
						}
					}else{
						$(".search-result-area").html(data.msg);
						$(".search-result-area").css("color","#C00");
					}
				}
			});
		}
	});
	
	$(".search-result-area").on("click","#add-friend",function(){
		var prompt = layer.prompt({title:'验证消息',value:'我是...',maxlength:20},function(message,index1){
			layer.close(index1);
			$.ajax({
				url:"/nebula/friends/add-friend.action",
				data: {
					respondent : $("#search-friend").val(),
					message : message
				},
				dataType: "json",
				success : function(data){
					if(data.msg == "exist"){
						parent.parent.layer.msg("该用户已请求添加您为好友 【<a id='agree' class='"+$("#search-friend").val()+"' href='javascript:;'>同意好友请求</a>】",{offset:"t",icon: 0,time:-1,closeBtn:2});
					}else{
						parent.parent.layer.msg(data.msg,{offset:"t",icon:1,time:2000});
					}
						parent.layer.close(index);
				}
			});
		});
	});
	
	$(".search-result-area").on("click","#share-file",function(){
		var share = parent.layer.open({
			type: 2,
			area: ['771px','470px'],
			title: '文件列表',
			skin:'mySkin',
			content:"/nebula/file-share.action?username="+$("#search-friend").val().trim(),
		});
		parent.layer.close(index);
	});
});
</script>
</body>
</html>
